package studentmanager;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Student {
	private String rollNum;
	private String firstName;
	private String lastName;
	private String address;
	private Mark[] mark = new Mark[4];
	double sumP = 0.0;
	double sumW = 0.0;
	double avgP;
	double avgW;
	private Student[] array_student = new Student[2];
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public Student() {

	}

	public Student(String rollNum, String firstName, String lastName,
			String address) {
		super();
		this.rollNum = rollNum;
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
	}

	public void newStudent() {
		System.out.println("NHAP SINH VIEN MOI");
		System.out.println("------------------");
		for (int i = 0; i < array_student.length; i++) {
			try {
				BufferedReader br = new BufferedReader(new InputStreamReader(
						System.in));
				System.out.println("Ma SV: ");
				String rollNum = br.readLine();
				System.out.println("Ten: ");
				String firstName = br.readLine();
				System.out.println("Ho: ");
				String lastName = br.readLine();
				System.out.println("Dia chi: ");
				String address = br.readLine();
				System.out.println("------------------");
				array_student[i] = new Student(rollNum, firstName, lastName,
						address);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void displayStudent() {
		System.out.println("--------------");
		System.out.println("SINH VIEN");
		System.out.println("--------------");
		for (int i = 0; i < array_student.length; i++) {
			System.out.println("Ma SV: " + array_student[i].rollNum);
			System.out.println("Ten: " + array_student[i].firstName);
			System.out.println("Ho: " + array_student[i].lastName);
			System.out.println("Dia chi: " + array_student[i].address);
			System.out.println("-------------");
			System.out.println("BANG DIEM");
			System.out.println("-------------");
			System.out.println("STT|MON|TH|LT");
			for (int j = 0; j < mark.length; j++) {
				array_student[i].mark[j].showMark();
			}
			System.out.println("---------------");
		}
	}

	public void displayAvgMark() {
		int k, j;

		for (j = 0; j < array_student.length; j++) {

			for (k = 0; k < array_student[j].mark.length; k++) {
				array_student[j].sumP = array_student[j].sumP
						+ array_student[j].mark[k].getpMark();
				array_student[j].sumW = array_student[j].sumW
						+ array_student[j].mark[k].getwMark();
			}
			array_student[j].avgP = array_student[j].sumP / k;
			array_student[j].avgW = array_student[j].sumW / k;
			System.out.println("DIEM TRUNG BINH");
			System.out.println("---------------");
			System.out.println("Sinh vien: " + array_student[j].firstName);
			System.out.println("TH: " + array_student[j].avgP);
			System.out.println("LT: " + array_student[j].avgW);
		}
	}

	public void addMarkForStudent() {
		String sub = "";
		Double wM = 0.0;
		Double pM = 0.0;
		for (int j = 0; j < array_student.length; j++) {
			System.out.println("Nhap diem cho sinh vien: "
					+ array_student[j].firstName);
			for (int i = 0; i < mark.length; i++) {
				try {
					System.out.println("Mon hoc: ");
					sub = br.readLine();
					System.out.println("Diem LT: ");
					wM = Double.parseDouble(br.readLine());
					System.out.println("Diem TH: ");
					pM = Double.parseDouble(br.readLine());
					array_student[j].mark[i] = new Mark(sub, wM, pM);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
